@extends('base')

@section('content')
<form class="layui-form" name="add_form" lay-filter="add_form">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">标签名：</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" placeholder="请输入名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序值：</label>
                <div class="layui-input-block">
                    <input type="number" name="sort" value="0" lay-verify="required" placeholder="请输入排序值" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否显示：</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="显示" checked>
                    <input type="radio" name="status" value="2" title="隐藏">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="tags-save"><i class="layui-icon layui-icon-ok"></i>提交</button>
            <button type="reset" class="pear-btn pear-btn-sm"><i class="layui-icon layui-icon-refresh"></i>重置</button>
        </div>
    </div>
</form>
@endsection

@section('js')
<script>
    layui.use(['form', 'jquery'], function() {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(tags-save)', function(data) {
            $.ajax({
                url: "/tags/add",
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(result) {
                    if (result.status) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("tags-table");
                        });
                    } else {layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
@endsection
